#include "board_bsp.h"
#include "stdio.h"
#include "usart.h"
#include "app_lcd_main.h"
#include "mid_FSM.h"
#include "mid_button.h"

bool rs485AppInit(void);
void rs485AppLoop(void);
bool MainCMD(uint8_t cmd);
bool rs485AddCMD(uint8_t cmd);

void app_init(void)
{
    rs485Init();
    rs485AppInit();
		mid_button_init();
    TFT_UIManager_init();
}


void app_loop(void)
{
		static uint32_t last_5ms = 0;
    static uint32_t last_2s = 0;
    static uint32_t last_500ms = 0;
    uint32_t now = HAL_GetTick();
		if (now - last_2s >= 2000)
    {
        rs485AddCMD(1);
        last_2s = now;
    }
		
		if (now - last_5ms >= 5)
    {
        button_ticks();

        last_5ms = now;
    }
 
		if (now - last_500ms >= 500)
    {
        last_500ms = now;
        state_machine_run();
    }
		
    rs485AppLoop();
}
